<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/base}">
<head>
    <title>待审核农户 - 暖心助农选品平台</title>
</head>
<body>
    <div layout:fragment="content">
        <h3 class="mb-4">待审核农户</h3>
        
        <div th:if="${pendingFarmers.empty}" class="alert alert-info">
            没有待审核的农户。
        </div>

        <div th:unless="${pendingFarmers.empty}" class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>用户名</th>
                        <th>真实姓名</th>
                        <th>联系电话</th>
                        <th>地址</th>
                        <th>注册时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr th:each="farmer : ${pendingFarmers}">
                        <td th:text="${farmer.username}">用户名</td>
                        <td th:text="${farmer.realName}">真实姓名</td>
                        <td th:text="${farmer.phone}">联系电话</td>
                        <td th:text="${farmer.address}">地址</td>
                        <td th:text="${#dates.format(farmer.createTime, 'yyyy-MM-dd HH:mm:ss')}">注册时间</td>
                        <td>
                            <button class="btn btn-success btn-sm approve-btn" 
                                    th:data-id="${farmer.id}">
                                通过审核
                            </button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

    <th:block layout:fragment="scripts">
        <script th:inline="javascript">
            $(document).ready(function() {
                $('.approve-btn').click(function() {
                    var btn = $(this);
                    var userId = btn.data('id');
                    
                    if (confirm('确定要通过这个农户的注册申请吗？')) {
                        $.post([[@{/admin/users/}]] + userId + '/approve')
                            .done(function(response) {
                                if (response === 'success') {
                                    btn.closest('tr').fadeOut(function() {
                                        $(this).remove();
                                        if ($('tbody tr').length === 0) {
                                            location.reload();
                                        }
                                    });
                                } else {
                                    alert('操作失败: ' + response);
                                }
                            })
                            .fail(function() {
                                alert('操作失败');
                            });
                    }
                });
            });
        </script>
    </th:block>
</body>
</html>
 